var setting;
var setTime;
var danmuindex = 0;
var _top=0;
var _left=$(window).width()+70;
var _height=$(window).height();
var ran;
$.getJSON("/web/home/screen/conf/liveid/"+liveid+"/type/msg_setting",function(data){
	setting = data;
});
function danmu(){
	var num = danmuarr.length;
		if(danmuindex >= num){
			danmuindex = 0;
		}
		setTime = setTimeout('danmu()',500);
		$(".s_show").append("<div><img src='"+danmuarr[danmuindex][0]+"'>"+danmuarr[danmuindex][1]+"</div>");
		$(".s_show").find("div:last").show(function(){
			var ranls = random(1,12);
			while(ran == ranls && danmuindex%12!=0){
				ranls = random(1,12);
			}
			ran = ranls;
			_top= 80*ran;
			if(_top>_height-100){
				_top = 80;
			}
			if(setting.speed == 1){
				var time=15000;
			}else if(setting.speed == 2){
				var time=11000;
			}else{
				var time=7000;
			}
			if(setting.text == 1){
				var _fontSize = '24px';
			}else if(setting.text == 2){
				var _fontSize = '36px';
			}else{
				var _fontSize = '48px';
			}
			var _color = getRandomColor()
			var len = danmuarr[danmuindex][1].length/20;
			var time = time-len*1000;
			var terminal = $(this).width()+50;
			if(setting.style == 1){
				$(this).css({left:_left,top:_top,color:_color,border:'3px solid ' + _color,fontSize:_fontSize});
				$(this).find('img').css({border:'3px solid ' + _color});
			}else{
				$(this).css({left:_left,top:_top,color:_color,background:'none',border:'none',fontSize:_fontSize});
				$(this).find('img').remove();
			}
			$(this).animate({left:"-"+terminal+"px"},time,function(){$(this).remove();});
			danmuindex++;
		});
}

//随机获取颜色值
function getRandomColor(){
	return '#'+(function(h){
		return new Array(7-h.length).join("0")+h
	})((Math.random()*0x1000000<<0).toString(16))
}

function random(min,max){
	return Math.floor(min+Math.random()*(max-min));
}